<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 31] 31.17 java.util.zip.ZipOutputStream (JDK 1.1)</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:36:46 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch31_16.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 31<br>The java.util.zip Package</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch32_01.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-31-SECT-17">31.17 java.util.zip.ZipOutputStream (JDK 1.1)</A></h2>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-31-SECT-17.1"></A></h3>
</DIV>

<P CLASS=para>
This class is a subclass of <tt CLASS=literal>DeflaterOutputStream</tt>
that writes data in ZIP file format to an output stream.
Before writing any data to the <tt CLASS=literal>ZipOutputStream</tt>, you
must begin an entry within the ZIP file with
<tt CLASS=literal>putNextEntry()</tt>.  The <tt CLASS=literal>ZipEntry</tt> object passed
to this method should specify at least a name for the entry.
Once you have begun an entry with <tt CLASS=literal>putNextEntry()</tt>,
you can write the contents of that entry with the
<tt CLASS=literal>write()</tt> methods.  When you reach the end of an
entry, you can begin a new one by calling
<tt CLASS=literal>putNextEntry()</tt> again, or you can close the current
entry with <tt CLASS=literal>closeEntry()</tt>, or you can close the stream
itself with <tt CLASS=literal>close()</tt>.

<P CLASS=para>
Before beginning an entry with <tt CLASS=literal>putNextEntry()</tt>, you
can set the compression method and level with
<tt CLASS=literal>setMethod()</tt> and <tt CLASS=literal>setLevel()</tt>.  The constants
<tt CLASS=literal>DEFLATED</tt> and <tt CLASS=literal>STORED</tt> are the two legal values
for <tt CLASS=literal>setMethod()</tt>.  If you use <tt CLASS=literal>STORED</tt>,
the entry is stored in the ZIP file without any
compression.  If you use <tt CLASS=literal>DEFLATED</tt>, you can also
specify the compression speed/strength trade-off by passing a
number from 1 to 9 to <tt CLASS=literal>setLevel()</tt>, where 9 gives the
strongest and slowest level of compression.  You can also
use the constants <tt CLASS=literal>Deflater.BEST_SPEED</tt>,
<tt CLASS=literal>Deflater.BEST_COMPRESSION</tt>, and
<tt CLASS=literal>Deflater.DEFAULT_COMPRESSION</tt> with the
<tt CLASS=literal>setLevel()</tt> method.

<P CLASS=para>
Note that if you are simply storing an entry without
compression, the ZIP file format requires that you specify,
in advance, the entry size and CRC-32 checksum in the
<tt CLASS=literal>ZipEntry</tt> object for the entry.  An exception is
thrown if these values are not specified or are incorrectly
specified.

<DIV CLASS=screen>
<P>
<PRE>
public class <tt CLASS=literal>ZipOutputStream</tt> extends DeflaterOutputStream {
    // <tt CLASS=literal>Public Constructor</tt>
            public <tt CLASS=literal>ZipOutputStream</tt>(OutputStream <tt CLASS=literal>out</tt>);
    // <tt CLASS=literal>Constants</tt>
            public static final int <tt CLASS=literal>DEFLATED</tt>;
            public static final int <tt CLASS=literal>STORED</tt>;
    // <tt CLASS=literal>Public Instance Methods</tt>
            public void <tt CLASS=literal>close</tt>() throws IOException;  //<tt CLASS=literal> Overrides DeflaterOutputStream</tt>
            public void <tt CLASS=literal>closeEntry</tt>() throws IOException;
            public void <tt CLASS=literal>finish</tt>() throws IOException;  //<tt CLASS=literal> Overrides DeflaterOutputStream</tt>
            public void <tt CLASS=literal>putNextEntry</tt>(ZipEntry <tt CLASS=literal>e</tt>) throws IOException;
            public void <tt CLASS=literal>setComment</tt>(String <tt CLASS=literal>comment</tt>);
            public void <tt CLASS=literal>setLevel</tt>(int <tt CLASS=literal>level</tt>);
            public void <tt CLASS=literal>setMethod</tt>(int <tt CLASS=literal>method</tt>);
            public synchronized void <tt CLASS=literal>write</tt>(byte[] <tt CLASS=literal>b</tt>, int <tt CLASS=literal>off</tt>, int <tt CLASS=literal>len</tt>) throws IOException;  //<tt CLASS=literal> Overrides DeflaterOutputStream</tt>
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-31-SECT-17.2">Hierarchy:</A></h3>

<P CLASS=para>
Object->OutputStream->FilterOutputStream->DeflaterOutputStream->ZipOutputStream

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch31_16.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch32_01.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>java.util.zip.ZipInputStream (JDK 1.1)</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Class, Method, and Field Index</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
